package com.sdx.common.utils;

import org.springframework.context.ApplicationContext;

/**
 * @ClassName SpringUtils
 * @Description: spring的工具类
 * @author: tanbaocai
 * @date: 2018/7/31 16:18
 */
public class SpringUtils {
	private static ApplicationContext applicationContext;
	public static void setApplicationContext(ApplicationContext applicationContext) {
		SpringUtils.applicationContext = applicationContext;
	}
	//通过name获取 Bean.
	public static Object getBean(String name){
		return SpringUtils.applicationContext.getBean(name);

	}

	//通过class获取Bean.
	public static <T> T getBean(Class<T> clazz){
		return SpringUtils.applicationContext.getBean(clazz);
	}

	//通过name,以及Clazz返回指定的Bean
	public static <T> T getBean(String name,Class<T> clazz){
		return SpringUtils.applicationContext.getBean(name, clazz);
	}
}
